package com.yc.navy.dayfresh.service.Impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.yc.navy.dayfresh.bean.TypeInfo;
import com.yc.navy.dayfresh.enums.ResultEnum;
import com.yc.navy.dayfresh.mapper.ITypeInfoMapper;
import com.yc.navy.dayfresh.service.ITypeInfoService;
import com.yc.navy.dayfresh.util.FindByPageParamUtil;
import com.yc.navy.dayfresh.util.StringUtil;
import com.yc.navy.dayfresh.vo.LayuiVO;

@Service
public class TypeInfoServiceImpl implements ITypeInfoService{
	@Autowired
	private ITypeInfoMapper typeInfoMapper;
	@Override
	public int add(TypeInfo tf) {
		if(StringUtil.checkNull(tf.getPic(),tf.getTname())) {
			return -1;
		}
		return typeInfoMapper.add(tf);
	}

	@Override
	public int update(TypeInfo tf) {
		if(StringUtil.checkNull(tf.getTno())) {
			return -1;
		}
		return typeInfoMapper.update(tf);
	}

	@Override
	public List<TypeInfo> finds() {
		return typeInfoMapper.finds();
	}

	@Override
	public int total() {
		return typeInfoMapper.total();
	}

	@Override
	public List<TypeInfo> findByPage(Map<String, Object> map) {
		return typeInfoMapper.findByPage(FindByPageParamUtil.findByPageParam(map));
	}

	@Override
	public LayuiVO findByPageForBack(Map<String, Object> map) {
		List<TypeInfo> list = typeInfoMapper.findByPage(FindByPageParamUtil.layuiFindByPageParam(map));
		if(list == null || list.isEmpty()) {
			return new LayuiVO(ResultEnum.DATA_NULL);
		}
		
		return new LayuiVO(typeInfoMapper.total(), list);
	}
}
